package com.suray.attendance.controller;

import com.suray.attendance.common.result.Result;
import com.suray.attendance.common.result.ResultCodeEnum;
import com.suray.attendance.db.service.ReportWorkInfoDBService;
import com.suray.attendance.model.vo.ProductionDataCollectVo;

import io.swagger.annotations.ApiOperation;
import lombok.extern.apachecommons.CommonsLog;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;


/**
 * Description: 报工模块控制层
 * Author: linyu
 * Date: 2023/11/23
 */
@RequestMapping("/api/production")
@RestController
@CommonsLog
public class ProductCollectController {

    @Resource
    private ReportWorkInfoDBService reportWorkInfoDBService;

    @ApiOperation(value = "新增报工数据到erp")
    @PostMapping(value = "/workReportDataToErp")
    public Result workReportDataToErp(@RequestBody List<ProductionDataCollectVo> productionData){
        if(productionData==null||productionData.size()==0){
            return Result.fail().code(ResultCodeEnum.DATA_NULL.getCode());
        }
        try {
            Boolean addResult = reportWorkInfoDBService.workReportDataToErp(productionData);
            if (addResult){
                return Result.ok();
            }
        } catch (Exception e) {
            e.printStackTrace();
            return Result.fail(e.getMessage());
        }
        return Result.fail();
    }
}
